import React, { Component } from 'react';
import MainBanner from './MainBanner'
import MainProductList from './MainProductList'
import axios from 'axios'

class Main extends Component {

  constructor(props) {
    super(props);
    this.state = {
      banners: [],
      productList: []
    }
  }

  //发送网络请求, 获取数据
  componentDidMount() {
    axios.get("http://123.207.32.32:8000/home/multidata").then(res => {
      const banner = res.data.data.banner.list;
      const recommend = res.data.data.recommend.list;
      this.setState({
        banners: banner,
        productList: recommend
      })
    })  
  }

  render() {
    const { banners, productList } = this.state;
    return ( 
      <div>
        <div>main</div>
        <MainBanner banners={banners} title={"轮播图"}></MainBanner>
        <MainBanner/>
        <MainProductList productList={productList}></MainProductList>
      </div>
     );
  }
}
 
export default Main;